package com.example.zhongshuishi.controller;

import com.example.zhongshuishi.entity.Tax;
import com.example.zhongshuishi.service.TaxService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 鑫程垬纾
 * @version 1.0
 * @description TODO
 * @date 2025/3/29 12:27
 */
@RestController
@RequestMapping("/api/tax")
public class TaxController {
    Logger logger = LoggerFactory.getLogger(TaxController.class);
    @Autowired
    private TaxService taxService;

    @PostMapping("/add")
    public ResponseEntity<?> addTax(@RequestBody Tax tax) throws Exception {
        if (tax.getStuId() == null || tax.getStuId()==0) {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("stuId is null");
        }
        if(tax.getKplx() == null || tax.getKplx() == ""){
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("kplx is null");
        }
        taxService.insertSelective(tax);
        return ResponseEntity.ok().body("保存成功");
    }

    //查询用户申请的发票
    @PostMapping("/get")
    public ResponseEntity<?> getTax(@RequestBody Tax tax) throws Exception {
        if (tax.getStuId() == null || tax.getStuId()==0) {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("stuId is null");
        }
        if(tax.getKplx() == null || tax.getKplx() == ""){
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("kplx is null");
        }
        List<Tax> taxes = taxService.selectList(tax);
        Tax tax1 = null;
        if (taxes != null && taxes.size() > 0) {
            tax1 = taxes.get(0);
            return ResponseEntity.ok().body(tax1);
        }
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("未申请发票");
    }
}


